
function p_m_an = func_p_m_analytically(m, CONSTS, span, plot_data)

    p_low = span(1); 
    p_high = span(2);
    num_intervals = p_high*7; 
    p_vec = linspace(p_low, p_high, num_intervals)';
    
    func = @(p_vec)abs(func_delta2_approximated(p_vec, m, CONSTS, false));

    if (plot_data)
        func_for_plot = abs(func_delta2_approximated(p_vec, m, CONSTS, false));
        figure; plot(p_vec, func_for_plot, 'b.-'); title('|det_analyt|');
    end
    
    for i = 1:size(p_vec,1)
        x0 = fminsearch(func, p_vec(i));
        x(i) = x0;
    end
    
    j=0;
    for ii = 2:size(x, 2)
        if(abs(x(ii)-x(ii-1))>1e-3)
            j = j+1;
            x_pref(j)=x(ii);
        end
    end
    hh=0;
    for k = 1:size(x_pref, 2)
        x_k = x_pref(k);
        h=1;
        for kk = k+1:size(x_pref,2)
            if(abs(x_k-x_pref(kk))<1e-3)
                h = h+1;
            end
        end
        if(h==1)
            hh = hh + 1;
            p_m_temp(hh) = x_k;
        end
    end
    
    ll = 0;
    for l = 1:size(p_m_temp, 2)
        if(p_m_temp(l)>=p_low && p_m_temp(l)<=p_high)
            ll = ll+1;
            p_m_pref(ll) = p_m_temp(l);
        end
    end
    
    p_m_an = sort(p_m_pref)';
    
end


